package uscdb.model;

import java.sql.Clob;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.search.annotations.Analyzer;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.FieldBridge;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Store;

import uscdb.util.StringUtil.ClobFieldBridge;

@Entity
@Table(name = "tlogic")
@DynamicInsert(true)
@DynamicUpdate(true)
@Indexed
// @Analyzer(impl = org.apache.lucene.analysis.standard.StandardAnalyzer.class)
@Analyzer(impl = org.apache.lucene.analysis.cn.smart.SmartChineseAnalyzer.class)
// @Analyzer(impl = org.apache.lucene.analysis.cn.ChineseAnalyzer.class)
public class Tlogic implements java.io.Serializable {

	private static final long serialVersionUID = -7661435050865430383L;
	private String id;

	/**
	 * logic名
	 */
	private String title;
	/**
	 * 一个完整的logic
	 */
	private Clob content;
	/**
	 * 导入系统的时间
	 */
	private Date createdatetime;
	/**
	 * 最后一次修改的时间
	 */
	private Date modifydatetime;
	/**
	 * 点击率
	 */
	private Long heat = 0L;

	/**
	 * 该logic所属的logic文件
	 */
	private Tlogicfile tlogicfile;

	@Column(name = "heat")
	public Long getHeat() {
		return heat;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "TLOGICFILE_ID")
	public Tlogicfile getTlogicfile() {
		return tlogicfile;
	}

	public void setTlogicfile(Tlogicfile tlogicfile) {
		this.tlogicfile = tlogicfile;
	}

	public void setHeat(Long heat) {
		this.heat = heat;
	}

	@Id
	@Column(name = "ID", unique = true, nullable = false, length = 36)
	@DocumentId
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "title")
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(name = "content")
	@Field(store = Store.YES) // 表示存储索引
	@FieldBridge(impl = ClobFieldBridge.class)
	public Clob getContent() {
		return content;
	}

	public void setContent(Clob content) {
		this.content = content;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "CREATEDATETIME", length = 19)
	public Date getCreatedatetime() {
		return createdatetime;
	}

	public void setCreatedatetime(Date createdatetime) {
		this.createdatetime = createdatetime;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "MODIFYDATETIME", length = 19)
	// @Field(index = Index.NO) // 表示不进行分词处理
	public Date getModifydatetime() {
		return modifydatetime;
	}

	public void setModifydatetime(Date modifydatetime) {
		this.modifydatetime = modifydatetime;
	}

	@Override
	public String toString() {
		return "Tlogic [id=" + id + ", title=" + title + ", content=" + content + ", createdatetime=" + createdatetime
				+ ", modifydatetime=" + modifydatetime + ", heat=" + heat + ", tlogicfile=" + tlogicfile + "]";
	}

}
